
#import "adPlugin.h"

#import <BUAdSDK/BUAdSDK.h>
@interface csjAd : NSObject<BUSplashAdDelegate>
    @property (strong, nonatomic) BUSplashAdView *splashAdView;
@end

@implementation csjAd

- (void) splashAd {
    [BUAdSDKManager setAppID:@"5310402"];
    CGRect frame = [UIScreen mainScreen].bounds;
    self.splashAdView = [[BUSplashAdView alloc] initWithSlotID:@"887821172" frame:frame];
    self.splashAdView.tolerateTimeout = 10;
    self.splashAdView.delegate = self;
    
    [self.splashAdView loadAdData];
    UIViewController *root = [[[UIApplication sharedApplication] windows] lastObject].rootViewController;
    [root.view addSubview:self.splashAdView];
    self.splashAdView.rootViewController = root;
}


- (void)splashAdDidLoad:(BUSplashAdView *)splashAd {
    NSLog(@"load");
}

- (void)splashAd:(BUSplashAdView *)splashAd didFailWithError:(NSError * _Nullable)error {
    [self.splashAdView removeFromSuperview];
}

- (void)splashAdWillVisible:(BUSplashAdView *)splashAd {
    NSLog(@"");
}

- (void)splashAdDidClick:(BUSplashAdView *)splashAd {
    NSLog(@"");
}

- (void)splashAdDidClose:(BUSplashAdView *)splashAd {
    [self.splashAdView removeFromSuperview];
}

- (void)splashAdWillClose:(BUSplashAdView *)splashAd {
    NSLog(@"");
}

- (void)splashAdDidCloseOtherController:(BUSplashAdView *)splashAd interactionType:(BUInteractionType)interactionType {
    [self.splashAdView removeFromSuperview];
}

- (void)splashAdDidClickSkip:(BUSplashAdView *)splashAd {
    [self.splashAdView removeFromSuperview];
}

- (void)splashAdCountdownToZero:(BUSplashAdView *)splashAd {
    [self.splashAdView removeFromSuperview];
}

@end

@implementation adPlugin

-(instancetype) init {
    self = [super init];
    self.adContext = [NSMutableDictionary dictionary];
    return self;
}

-(void) adStart {
    csjAd *ad = [[csjAd alloc] init];
    [ad splashAd];
    [[self adContext] setValue:ad forKey:@"csjAdIns"];
}

-(void) adLoad:(NSString* )route{
    
}
@end
